//
//  LCZFirstTableViewCell.m
//  PersonalNews
//
//  Created by Golibyo on 15/11/27.
//  Copyright © 2015年 changshuhua. All rights reserved.
//

#import "LCZFirstTableViewCell.h"
#import "LCZSonCollectionViewCell.h"
@implementation LCZFirstTableViewCell

- (void)setTListArr:(NSMutableArray *)tListArr {
    if (_tListArr != tListArr) {
        _tListArr = tListArr;
    }
    [self.collectionView reloadData];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
//        self.backgroundColor = [UIColor grayColor];
        [self createView];
    }
    return self;
}

- (void)createView {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(WIDTH / 3.0, HEIGHT / 667.0 * 220);
    flowLayout.minimumLineSpacing = 0;
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.scrollDirection = 1;
    self.collectionView = [[LCZBaseCollectionView alloc] initWithFrame:CGRectMake(0, HEIGHT / 667.0 * 30, WIDTH, HEIGHT /667.0 * 220) collectionViewLayout:flowLayout];
    [self addSubview:self.collectionView];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    //    self.collectionView.bounces = NO;
    [self.collectionView registerClass:[LCZSonCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.pagingEnabled = YES;
    self.typeLabel = [[LCZBaseLabel alloc] initWithFrame:CGRectMake(WIDTH / 375.0 * 10, 0, WIDTH / 375.0 * 100, HEIGHT / 667.0 * 30)];
    self.lineLabel = [[LCZBaseLabel alloc] initWithFrame:CGRectMake(0, HEIGHT / 667.0 * 25, WIDTH, HEIGHT / 667.0 * 1)];
    self.lineLabel.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.lineLabel];
    self.inLabel = [[LCZBaseLabel alloc] initWithFrame:CGRectMake(WIDTH / 375.0 * 300, 0, WIDTH /375.0 * 75, HEIGHT / 667.0 * 30)];
    [self.contentView addSubview:self.inLabel];
//    self.typeLabel.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.typeLabel];
    self.inLabel.textAlignment = NSTextAlignmentCenter;
//    self.inLabel.text = @"进入>";
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    LCZSonCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.label.text = self.tListArr[indexPath.row][@"tname"];
    [cell.myImageView sd_setImageWithURL:[NSURL URLWithString:self.tListArr[indexPath.row][@"radio"][@"imgsrc"]]];
    cell.detailLabel.text = self.tListArr[indexPath.row][@"radio"][@"title"];
    cell.numberLabel.text = [NSString stringWithFormat:@"%.1f万", [self.tListArr[indexPath.row][@"playCount"] floatValue] / 10000.0];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%ld", indexPath.row);
    //创建一个消息对象
    NSLog(@"%@", self.tListArr[indexPath.row][@"tid"]);
    NSNotification * notice = [NSNotification notificationWithName:@"123" object:nil userInfo:@{@"1":self.tListArr[indexPath.row][@"tid"]}];
    //发送消息
   
    [[NSNotificationCenter defaultCenter] postNotification:notice];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
